# 使用openai的API风格调用ollama
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="not-needed"
)

chat_completion = client.chat.completions.create(
    model="qwen2.5:0.5b",
    messages=[
        {"role": "user", "content": "你好，请介绍下你自己。"}
    ]
)

print(chat_completion.choices[0])